<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="include/base.jsp" %>

<html >
<head>
	<meta charset="UTF-8">
	<title>凯盛项目管理系统</title>
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="css/loong.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body class="body">
	
	<%@ include file="include/top.jsp" %>
	
	
	<div class="container">
	  <div class="row row-inner">
		<%@ include file="include/left.jsp" %>
		
		<div class="span8">
			<ul class="breadcrumb" style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:15px">
				<li class="active">
					<a href="idea.html"><i class="icon-fire"></i>${sessionScope.idea.title }</a>
				</li>
				
			</ul>
			<div class="wall">
				  <div class="page-header">
					<h3>${sessionScope.idea.title }&nbsp;&nbsp;<small>${sessionScope.idea.createtime }</small></h3>
				  </div>
				  <p>${sessionScope.idea.content }</p>
				  
				  <div class="line">
					评论
				  </div>
				  
					<textarea name="content" id="commentinner" class="span7" rows="5">请发表您对此想法的评论</textarea>
					<br/>
					<button  class="save btn btn-inverse">发布</button>
				  
				 <c:if test="${not empty  requestScope.commentList }">
				 	<c:forEach items="${requestScope.commentList }" var="item">
						 		 <blockquote>
								  <p> ${item.content} </p>
								  ${sessionScope.employee.username}<small>发表于： ${item.time}</small>
								  <a href="deleteComment.jspx?id=${item.id }" title="删除"><i class="icon-trash"></i></a>
								</blockquote>	
						 </c:forEach>
				 </c:if>
				
				<a href="ideaShow.jspx" style="color:#52264A">←返回想法列表</a>
			</div>
		</div>
	  </div>
	  <%@ include file="include/foot.jsp" %>
	</div>
	
	
	<script type="text/javascript" src="js/json.js"></script>
	<script type="text/javascript" src="js/jquery.js"></script>
	
	<script type="text/javascript">
		$(document).ready(function(){
				
			var xmlHttp;
	   	
	    	//创建Ajax引擎
	    	function createXmlHttp() {
	    		if(window.ActiveXObject) {
		    		//IE
	    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		    	} else {
		    		//Chrome firefox 
		    		xmlHttp = new XMLHttpRequest();
		    	}
	    	}
	    	function callback() {
	    		var serverCode = xmlHttp.readyState;
	    		if(serverCode == 4) {
	    			var httpCode = xmlHttp.status;
	    			if(httpCode == 200) {
	    				//接受服务器返回的字符串
	    				 var comment = eval('('+xmlHttp.responseText+')');
	    				 	
	    				 	$(".save").after("<blockquote><h5></h5><h6></h6><a></a></blockquote>");
	    				 	$("h5").first().html(comment.content);
	    				 	$("h6").first().html("发表于："+comment.time);
	    				 	$("blockquote a").first().attr("title","删除");
			   				$("blockquote a").first().attr("href","deleteComment.jspx?id="+comment.id);
			   				$("blockquote a").first().attr("class","icon-trash");
			   				
	    					
	    					
	    					
	   					
	    				
	    			} else {
	    				alert("服务器忙，请稍后...");
	    			}
	    		}
	    	}
	    	
    		
    		
    		
    		
	    	 $(".save").click(function(){
		    	 
		    	 var content= $("#commentinner").val();
		    	 
		    	 //1.创建Ajax引擎
	    		createXmlHttp();
	    		//2.告诉引擎请求的服务器地址(ajax.jspx)，请求方式(post)，是否异步请求(true)
	    		xmlHttp.open("post","savecomment.jspx",true);
	    		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	    		//3.设置回调函数
	    		xmlHttp.onreadystatechange = callback;
	    		
	    		//4.请求服务器
	    		xmlHttp.send("content="+content);
		    		
	    		
			 
			});
			 
			 $("#commentinner").focus(function(){
			
				$(this).val("");
			});
			
			
			
		
			
			
			
		});
	
	</script>
	
	
	
	
</body>
</html>